﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using NUnit.Framework;

namespace Comdiv.QWeb.Test.Renders
{
	[TestFixture]	
	public class form_render_test
	{
		[Action("test.form_render_test")]
		public class form_render_test_action:IAction {
			[Bind(Required = true)] private int x;
			public object Process(QWebContext context) {
				return "";
			}
		}

		[Test]
		public void check_it_is_working_on_default_configuration() {
			string result = docall();
			StringAssert.Contains("<!-- action form for test.form_render_test -->",result);
		}

		[Test]
		public void check_it_is_refs_to_js_and_css_on_default_configuration()
		{
			string result = docall();
			StringAssert.Contains("src='/test/tmp/_internal/actionform.js", result);
			StringAssert.Contains("href='/test/tmp/_internal/actionform.css", result);
		}

		[Test]
		public void check_is_executed_under_layout_by_default()
		{
			string result = docall();
			StringAssert.Contains("<html>",result);
			StringAssert.Contains("</html>",result);
		}

		private string docall() {
			var reg = new QWebServiceRegistry();
			var ctx = new QWebContext("http://localhost/test/form_render_test.form.qweb");
			var sw = ctx.Output = new StringWriter();
			var handler = new QWebHandler(reg);
			handler.ProcessRequest(ctx);
			var result = sw.ToString();
			Console.WriteLine(result);
			return result;
		}
	}
}
